With the development and advancement of communication technologies, network-related applications have become a part of our daily lives. For example, the rapidly growing peer-to-peer (P2P) networking technique enables a user to directly connect with another user over a P2P network so that voice chat, video transmission, or data sharing and exchange can be carried out.
In today's P2P networking environment, if one of two endpoints (i.e., network devices) respectively located behind different Network Address Translators (NATs) intends to send a message (e.g., a control message) to the other endpoint, the former endpoint must begin by contacting a tracker/coordinator to inquire about the address of the latter endpoint. Once the address is obtained, the former endpoint sends the message to the latter endpoint with the assistance of a protocol server (e.g., a STUN server, wherein STUN stands for Session Traversal Utilities for Network Address Translation) located in a public network. For example, a network device Host A is located behind a NAT router NAT X, a network device Host B is located behind a NAT router NAT Y, and a protocol server and a tracker/coordinator are located in a public network. When Host A intends to send a message to Host B, it is required that Host A send a first query request to the tracker/coordinator first. Based on the first query request, the tracker/coordinator sends a query response to Host A, wherein the query response indicates a second mapped address of Host B in NAT Y. After receiving the query response containing the second mapped address, Host A sends the message for Host B to the protocol server along with a first mapped address of Host A and the second mapped address. The protocol server then forwards the message and the first mapped address of Host A to the second mapped address of Host B in NAT Y, so as for NAT Y to relay the message to Host B. If Host B having received the message wishes to send a second message to Host A in reply, Host B must send the second message, the second mapped address, and the first mapped address to the protocol server, in order for the protocol server to forward the second message and the second mapped address to the first mapped address of Host A in NAT X, and consequently for NAT X to relay the second message to Host A.
The foregoing processes clearly show that, if two network devices respectively located behind different NATs are to communicate with each other, all the messages must be forwarded via a protocol server. Now that more and more people use P2P networks, the workload of such protocol servers is bound to increase. Further, should a protocol server fail to operate properly, all commands or control messages which are supposed to be forwarded by the protocol server between different endpoints will have problem reaching their destinations, and the P2P network in question will be down as a result. The issue to be addressed by the present invention, therefore, is to design a method for exchanging network messages in a distributed manner so that the work of message transmission in a P2P network system is not centralized in a protocol server.